home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-05 | 10.1 KB | 380 lines | [TEXT/MMCC] |
- //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
- //
- // OurDlog.c
- //
- // EXPLANATION
- //
- // History:
- //
- // DATE jb: Written
- //
- //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
-
-
- // __#Defines________________________________________________________________________
- typedef enum {
- eFindDeepest = 1,
- eFindBiggest,
- eMiniMax,
- eToggleMBar,
- eDemoFade
- } etDlogItems;
-
- #define kPseudoAlrtID 129
-
- // __#Headers________________________________________________________________________
- #include "Amalgam.h"
- #include "Menu.h"
- #include "FadeGDev.h"
- #include "OurDlog.h"
-
- // __#Protos_________________________________________________________________________
- // __ Macros_________________________________________________________________________
- // __ Enums__________________________________________________________________________
- // __ Typedefs_______________________________________________________________________
- // __ Static Protos__________________________________________________________________
- static void UpdateOurDialog( void );
- static void FindDeepest( void );
- static void FindBiggest( void );
- static void MiniMaxOurDlog( void );
- static void DoFade( void );
- static void PseudoAlert( Rect *centerRect );
-
- // __ Extern Globals_________________________________________________________________
- // __ Static Globals_________________________________________________________________
- // __ Functions______________________________________________________________________
-
-
- //____ HandleOurDlogEvent __________________________________________________________________________
- //
- // This is called from the main event-handling routine when IsDialogEvent says
- // that the event concerns our Modeless dialog. This function handles the
- // event, which it expects to find in the gTheEvent global.
- //
- // Returns void
- //
- Boolean HandleOurDlogEvent( void )
- {
- Boolean dealWithEvent;
- DialogPtr whichDlog;
- short itemHit;
- Boolean handledIt; //if handledIt, don't let our normal event loop handle the event
-
- handledIt = FALSE;
-
- switch (gTheEvent.what)
- {
- case nullEvent:
- break;
-
- case mouseDown:
- break;
-
- case keyDown:
- case autoKey:
- break;
-
- case updateEvt:
- if ((WindowPtr) gTheEvent.message == gMainDlogPtr)
- {
- BeginUpdate(gMainDlogPtr);
- UpdateOurDialog();
- EndUpdate(gMainDlogPtr);
- handledIt = TRUE;
- }
- break;
-
- }//switch (gTheEvent.what)
-
- //tell world if we've already dealt with the event.
- if (handledIt)
- return TRUE;
-
- //Process a single modeless dialog event
- dealWithEvent = DialogSelect( &gTheEvent, &whichDlog, &itemHit);
-
- //was there an event to handle occuring in our dialog? If not,
- //pass back FALSE so normal event loop will handle it.
- if ((!dealWithEvent) || (whichDlog != gMainDlogPtr))
- return FALSE;
-
- //the only things we should ever see here are button-hits
- switch (itemHit)
- {
- case eFindDeepest:
- FindDeepest();
- break;
-
- case eFindBiggest:
- FindBiggest();
- break;
-
- case eMiniMax:
- MiniMaxOurDlog();
- break;
-
- case eToggleMBar:
- gUserWantsMenuBar = !gUserWantsMenuBar;
- ToggleMenuBar(gUserWantsMenuBar);
- break;
-
- case eDemoFade:
- DoFade();
- break;
-
- default:
- break;
-
- }//switch itemHit
-
- //return TRUE, since we handled the event ourselves.
- return TRUE;
-
- }//HandleOurDlogEvent
-
-
- //____ UpdateOurDialog __________________________________________________________________________
- //
- // Normally called during an update event and sandwiched
- // between calls to BeginUpdate and EndUpdate.
- //
- // Returns void
- //
- static void UpdateOurDialog( void )
- {
-
- DrawDialog( gMainDlogPtr );
-
- }//UpdateOurDialog
-
-
- //____ ZoomOurDialog __________________________________________________________________________
- //
- // User has clicked in zoombox. If there's only one screen, let system do it's usual
- // job of zooming window; if there's more than one screen, and we're zooming out,
- // find the screen we're mostly on, and then zoom to fill that screen.
- //
- // Dialog can be re-sized to original coordinates by holding down the option key
- // and clicking in the zoom box.
- //
- // Value passed is what was originally gotten from FindWindow
- //
- // Note that techniques similar to these are used when saving and restoring positons
- // of windows between sessions.
- //
- void ZoomOurDialog( short thePart )
- {
- WindowPeek aPeek;
- WStateData **hWSD; //state data holds the zoomed and un-zoomed rectangles of
- //windows
- Rect globalWindowStructRect;
- Rect globalWindowPortRect;
- GDHandle zoomToDevice;
- Rect zoomToRect;
-
- SetPort(gMainDlogPtr);
-
- //Hack: since we're not using a grow box in our dialog, yet we
- //let user zoom it, we need a way of returning to its original
- //size. Here, if the option key is down, we'll re-size the dialog
- //instead of zooming it.
- if (gTheEvent.modifiers & optionKey)
- {
- SizeWindow(gMainDlogPtr,gOriginalDlogPortRect.right - gOriginalDlogPortRect.left,
- gOriginalDlogPortRect.bottom - gOriginalDlogPortRect.top,
- TRUE);
- return;
- }
-
-
- aPeek = (WindowPeek)gMainDlogPtr;
- hWSD = (WStateData **)aPeek->dataHandle; //get a handle pointing to WStateData
-
- //if we're zooming out, determine which device we should zoom to; then,
- //create a nice rectangle defining thebounds of that device and stuff
- //it into the windows state data.
- if (inZoomOut == thePart)
- {
- globalWindowStructRect = mWindStructRect(gMainDlogPtr);
-
- globalWindowPortRect = gMainDlogPtr->portRect; //we'll need this to determine
- LocalToGlobalRect(&globalWindowPortRect); //size of title bar
-
- zoomToDevice = GetMaxIntersectDevice(globalWindowStructRect);
- zoomToRect = (**zoomToDevice).gdRect;
- if (zoomToDevice == gMainDevice)
- zoomToRect.top += LMGetMBarHeight();
- //make sure there's room for the title bar
- zoomToRect.top += (globalWindowPortRect.top - globalWindowStructRect.top);
-
- InsetRect(&zoomToRect, 8, 8);
-
- (**hWSD).stdState = zoomToRect;
- }
-
- //now that we've fooled with the values ZoomWindow will use,
- //let it do it's thing
- EraseRect(&gMainDlogPtr->portRect);
- ZoomWindow(gMainDlogPtr, thePart, TRUE);
- InvalRect(&gMainDlogPtr->portRect);
-
- }//ZoomOurDialog
-
-
-
-
- //____ FindDeepest __________________________________________________________________________
- //
- // Finds last, deepest screen in GDevice list
- //
- static void FindDeepest( void )
- {
- GDHandle theMaxDevice;
- Rect tempRect;
-
- SetRect( &tempRect, -32768, -32768, 32767, 32767 );
- theMaxDevice = GetMaxDevice(&tempRect);
-
- mAssert(NULL != theMaxDevice);
- mAssert(TestDeviceAttribute(theMaxDevice, screenDevice));
- mAssert(TestDeviceAttribute(theMaxDevice, screenActive));
-
- if (1 == gNumActiveScreens)
- {
- mAssert(theMaxDevice == gMainDevice);
- ParamAString("\pSince there’s only one device, it is also the deepest device");
-
- }
- else
- {
- ParamAString("\pThis is the last, deepest device in the GDevice list.");
- }
-
- tempRect = (**theMaxDevice).gdRect;
- PseudoAlert(&tempRect);
-
- }//FindDeepest
-
-
-
- //____ FindBiggest __________________________________________________________________________
- //
- // Finds last, largest screen in the GDevice list
- //
- static void FindBiggest( void )
- {
- GDHandle theLargestDevice;
- Rect tempRect;
-
- theLargestDevice = GetLargestAreaDevice();
-
- mAssert(NULL != theLargestDevice);
- mAssert(TestDeviceAttribute(theLargestDevice, screenDevice));
- mAssert(TestDeviceAttribute(theLargestDevice, screenActive));
-
- if (1 == gNumActiveScreens)
- {
- mAssert(theLargestDevice == gMainDevice);
- ParamAString("\pSince there’s only one device, it is also the largest device");
- }
- else
- {
- ParamAString("\pThis is the last, largest device found in the GDevice list.");
- }
-
- tempRect = (**theLargestDevice).gdRect;
- PseudoAlert(&tempRect);
-
- }//FindBiggest
-
-
- //____ MiniMaxOurDlog __________________________________________________________________________
- //
- // Toggles the size of our window from normal to filling up the device it is on.
- // When expanding, we remember the size and coordinates of our window; when
- // shrinking, we use those coordinates to resize and position our window.
- //
- static void MiniMaxOurDlog( void )
- {
- static Boolean isHuge = FALSE;
- static Rect originalGlobalPortRect; //original port rect in global coordinates
- Rect hugeRect;
- GDHandle aDev;
-
- SetPort(gMainDlogPtr);
-
- if (isHuge) //it's huge, so shrink it
- {
- HideWindow(gMainDlogPtr);
- MoveWindow(gMainDlogPtr, originalGlobalPortRect.left, originalGlobalPortRect.top, TRUE);
- SizeWindow(gMainDlogPtr,
- originalGlobalPortRect.right - originalGlobalPortRect.left,
- originalGlobalPortRect.bottom - originalGlobalPortRect.top, FALSE);
- ShowWindow(gMainDlogPtr);
-
- isHuge = FALSE;
- }
- else //it's normal, so expand it
- {
- originalGlobalPortRect = gMainDlogPtr->portRect;
- LocalToGlobalRect(&originalGlobalPortRect);
-
- aDev = GetMaxIntersectDevice(originalGlobalPortRect);
- hugeRect = (**aDev).gdRect;
-
- HideWindow(gMainDlogPtr);
- MoveWindow(gMainDlogPtr, hugeRect.left, hugeRect.top, TRUE);
- SizeWindow(gMainDlogPtr,
- hugeRect.right - hugeRect.left, hugeRect.bottom - hugeRect.top, FALSE);
- ShowWindow(gMainDlogPtr);
-
- isHuge = TRUE;
- }
- }//MiniMaxOurDlog
-
-
- //____ DoFade __________________________________________________________________________
- //
- // Fade out, delay a little while (like we're doing something) and fade back in.
- //
- static void DoFade( void )
- {
- #define kFadeSpeed 100
-
- long aLong;
-
- FadeWindowsGDev( gMainDlogPtr, kFadeSpeed, eFade_FadeOutCommand );
-
- Delay(45, &aLong); //delay 3/4 of a second
-
- FadeWindowsGDev( gMainDlogPtr, kFadeSpeed, eFade_FadeInCommand );
-
-
- }//DoFade
-
-
- //____ PseudoAlert __________________________________________________________________________
- //
- // Presents a dialog posing as an alert. Since it's a dialog, however,
- // we can easily place it where we want. Pass in a rectangle for the
- // dialog to be centered in. Of course, you should already have
- // ParamText'd whatever it is you want to say. Dialog goes away when
- // there's a key press or a mouse click.
- //
- static void PseudoAlert( Rect *centerRect )
- {
- DialogPtr pseudoAlrt;
-
- pseudoAlrt = GetNewDialog( kPseudoAlrtID, NULL, (WindowRef) -1 );
- if (NULL == pseudoAlrt)
- return;
-
- CenterWindowInRect(pseudoAlrt, centerRect, TRUE);
-
- ShowWindow(pseudoAlrt);
- DrawDialog(pseudoAlrt);
- WaitForQuit();
-
- DisposeDialog(pseudoAlrt);
-
- }//PseudoAlert